#ifndef ALTMATERIALWIDGET_H
#define ALTMATERIALWIDGET_H

#include <QWidget>

class QMenu;
class QPushButton;
class QTableWidget;

namespace Alt {
     /*! Widget for editing / viewing material names. */
     class MaterialWidget : public QWidget {
          Q_OBJECT
     public:
          /*! Default constructor.
               \param readOnly Whether the widget is read-only.
               \param parent The parent object. */
          MaterialWidget(bool readOnly = true, QWidget* parent = 0);

          /*! Whether the widget is read-only. */
          bool readOnly() const;

          /*! Set whether the widget is read-only.
               \param readOnly Whether the widget is read-only. */
          void setReadOnly(bool readOnly);

     public slots:
          /*! Export materials to a file. */
          void exportMaterials();

          /*! Prompts the user for a material ID, and scrolls to the specified material. */
          void goToMaterialId();

          /*! Prompts the user for a material name, and scrolls to the specified material. */
          void goToMaterialName();

          /*! Import materials from a file. */
          void importMaterials();

          /*! Inserts a material after currently selected one. */
          void insertMaterial();

          /*! Triggered when a context menu is requested for the table widget.
               Generates a context menu with the "Go to material ID" and "Go to material name" items.
               The "Insert" and "Remove" items are also provided is readOnly() is false. */
          void materialTableContextMenu(const QPoint& pos);

          /*! Reloads materials from the Alt settings file. */
          void refreshMaterials();

          /*! Removes the currently selected material. */
          void removeMaterial();

          /*! Saves changes to the Alt settings file. */
          void saveMaterials();

     private:
          /*! Initializes the widget. */
          void init();

          /*! Export materials to file button. */
          QPushButton* m_exportButton;

          /*! Import materials from file button. */
          QPushButton* m_importButton;

          /*! Context menu for material table widget. */
          QMenu* m_materialTableContextMenu;

          /*! Context menu for material table widget when in read-only mode. */
          QMenu* m_materialTableContextMenuReadOnly;

          /*! Table in which the first column contains material IDs, and the second column contains the corresponding material names. */
          QTableWidget* m_materialTableWidget;

          /*! Refresh materials buttom. */
          QPushButton* m_refreshButton;

          /*! Whether the widget is read-only. */
          bool m_readOnly;

          /*! Save materials button. */
          QPushButton* m_saveButton;
     };
}

#endif
